<%--
    Document   : modifyOrder
    Created on : 2011-5-18, 22:55:36
    Author     : tecton
--%>

<%@page import="com.dairy.structures.Orders"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript">
        function submitForm(){
            var duration = document.getElementById('duration');
            var number = document.getElementById('number');
            var day_of_week = document.getElementById('day_of_week');
            var id_company = document.getElementById('id_company');
            var d = duration.value;
            var n = number.value;
            var dow = day_of_week.value;
            var ic = id_company.innerHTML;

            var loc = "./modifyOrders.do?duration=" + d + "&number=" + n 
                + "&dow=" + dow + "&ic=" + ic;
            window.location = loc;
        }
        function submitItem(id){
            var ID = document.getElementById(id);
            window.location = "./modifyOrders.do?name=" + ID.innerHTML;
        }
    </script>
    
    <script type="text/javascript" src="./scripts/jquery-1.2.1.js"></script>
    <script type="text/javascript">
        $(function(){
            $('input[id=number]').change(function(){
                var totalPrice = $('input[id=number]').val() * $('#price').attr('price');
                totalPrice = Math.floor(totalPrice * 100) / 100;
                $('#price').text(totalPrice);
            })
            $(document).ready(function(){
                var totalPrice = $('input[id=number]').val() * $('#price').attr('price');
                totalPrice = Math.floor(totalPrice * 100) / 100;
                $('#price').text(totalPrice);
            })
        });
    </script>
    
    <title>订奶系统</title>
    <link rel="stylesheet" type="text/css" href="./home_style.css"/>
    <%
        String show = request.getAttribute("show").toString();
        Object success = request.getAttribute("success");
    %>
</head>

<body>
    <div class="wrapper">
        <div class="header">
            <h1>User's Orders Information</h1>
        </div>

        <div class="content">

            <div class="primary">
                <table border="1">
                    <tr>
                        <th>id</th>
                        <th>username</th>
                        <th>name</th>
                        <th>job_number</th>
                        <th>day_of_week</th>
                        <th>duration</th>
                        <th>number</th>
                        <th>Action</th>
                    </tr>
                    <% int i = 0;%>
                    <logic:iterate id="orders" name="UserOrdersForm" property="orders"><tr>
                            <td><bean:write name="orders" property="id" /></td>
                            <td><bean:write name="orders" property="username" /></td>
                            <td id ="<%="td" + i%>"><bean:write name="orders" property="name" /></td>
                            <td><bean:write name="orders" property="job_number" /></td>
                            <td><bean:write name="orders" property="day_of_week" /></td>
                            <td><bean:write name="orders" property="duration" /></td>
                            <td><bean:write name="orders" property="number" /></td>
                            <td><button onclick="javascript:submitItem('<%="td" + i++%>');">Change</button></td>
                        </tr></logic:iterate>
                    </table>
                    <% if (success != null)
                    {
                    String suc = success.toString();
                    if (suc.equals("true")){
                    %>
                    <h1>modification succeeded</h1>
                    <%
                        }else{
                    %>
                    <h1>modification failed</h1>
                    <%
                    }}
                    %>
                
                <% if (show.equals("true")){%>
                <bean:define id="anorder" name="UserOrdersForm" property="order"></bean:define>
                <br/>
                    <table>
                        <tr>
                            <td style="width:150px" height="30px">
                                <label>ID:</label>
                            </td>
                            <td>
                                <bean:write name="anorder" property="id"/>
                            </td>
                        </tr>
                        <tr>
                            <td height="30px">
                                <label>User Name:</label>
                            </td>
                            <td>
                                <bean:write name="anorder" property="username"/>
                            </td>
                        </tr>
                        <tr>
                            <td height="30px">
                                <label>Product Name:</label>
                            </td>
                            <td>
                                <bean:write name="anorder" property="name" />
                            </td>
                        </tr>
                        <tr>
                            <td height="30px">
                                <label>Company ID:</label>
                            </td>
                            <td>
                                <label id ="id_company"><bean:write name="anorder" property="id_company" /></label>
                            </td>
                        </tr>
                        <tr>
                            <td height="30px">
                                <label>Day of week:</label>
                            </td>
                            <td>
                                <input type="text" name="day_of_week" id="day_of_week"
                           value="<bean:write name="anorder" property="day_of_week"/>"/>
                            </td>
                        </tr>
                        <tr>
                            <td height="30px">
                                <label>Duration:</label>
                            </td>
                            <td>
                                <input type="text" name="duration" id="duration"
                           value ="<bean:write name="anorder" property="duration"/>"/>
                            </td>
                        </tr>
                        <tr>
                            <td height="30px">
                                <label>Number: </label>
                            </td>
                            <td>
                                <input type="text" name="number" id="number"
                           value ="<bean:write name="anorder" property="number"/>"/>
                            </td>
                        </tr>
                        <tr>
                            <td height="30px">
                                <label>Price: </label>
                            </td>
                            <td>
                                <label id ="price" price="<bean:write name="anorder" property="price"/>"></label>
                            </td>
                        </tr>
                        <tr>
                            <td height="30px">
                                <button type="submit" name="modify" onclick="javascript:submitForm()">Modify</button>
                            </td>
                        </tr>
                    </table>

<!--                    <p>ID: <bean:write name="anorder" property="id" /></p>
                    <p>User name: <bean:write name="anorder" property="username" /></p>
                    <p>Product name: <bean:write name="anorder" property="name" /></p>
                    <p>Day of week: </p>
                    <input type="text" name="day_of_week" id="day_of_week"
                           value="<bean:write name="anorder" property="day_of_week"/>"/><br />
                    <p>Duration:</p>
                    <input type="text" name="duration" id="duration"
                           value ="<bean:write name="anorder" property="duration"/>"/><br />
                    <p>Number: </p>
                    <input type="text" name="number" id="number"
                           value ="<bean:write name="anorder" property="number"/>"/><br />
                    <p id ="price" price="<bean:write name="anorder" property="price"/>">
                        Price: </p>
                    <button onclick="javascript:submitForm();">BUY NOW</button>-->
                <% } %>
            </div>

            <div class="secondary">
                <ul class="nav">
                    <li class="first"><a href="user/index.do">Home</a></li>
                    <li><a href="./logout.do">logout</a></li>
                    <li><a href="./modifyPersonInfo.do">modify information</a></li>
                    <li><a href="./modifyOrders.do">orders</a></li>
                    <li><a href="./viewProduct.do">view product</a></li>
                </ul>
            </div>
        </div>

        <div class="footer">
            <p>Dairy Product Ordering System - All Rights Reserved</p>
        </div>
    </div>
</body>
</html>